package com.example;

import com.example.common.filter.XssFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 添加@Configuration注解,标识这是一个配置类
 * @author wangxiaoyun
 */
@Configuration
public class WebConfiguration {

    @Value("${sensitiveFilePath}")
    private String sensitiveFilePath ;


    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        registration.setName("XssFilter");
        registration.addInitParameter("sensitiveFilePath", sensitiveFilePath);
        //执行顺序，order越小越先执行
        registration.setOrder(1);
        return registration;
    }
}